package com.hongkuncheng.cms.controller.admin;

import org.hibernate.LockMode;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Controller;
import com.hongkuncheng.cms.controller.BaseController;
import com.hongkuncheng.cms.helper.PageHelper;
import com.hongkuncheng.cms.model.Webinfo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 网站基础设置
 *
 * @author 洪坤成
 */
@Controller
@Transactional
@RequestMapping("admin/webinfo")
public class AwebinfoController extends BaseController {

    // 网站基础设置
    @RequestMapping
    public String index() {
        webinfo = factorySession.get(Webinfo.class, 1);
        request.setAttribute("webinfo", webinfo);
        return view();
    }

    // 网站基础设置处理
    @RequestMapping("update")
    @ResponseBody
    public void update() {
        checkAdminPermission("yunwei_webmaintain_webinfo");
        webinfo = factorySession.load(Webinfo.class, 1, LockMode.PESSIMISTIC_WRITE);
        webinfo.setTitle(request.getParameter("title"));
        webinfo.setKeywords(request.getParameter("keywords"));
        webinfo.setDescription(request.getParameter("description"));
        PageHelper.alertAndRedirect("保存成功", "./");
    }

}
